<script setup>
import { ref } from 'vue'

// 权限数据
const permissions = ref([
  {
    id: 1,
    module: '评测管理',
    permissions: ['查看评测', '添加评测', '编辑评测', '删除评测'],
    status: 'active'
  },
  {
    id: 2,
    module: '报告管理',
    permissions: ['查看报告', '生成报告', '导出报告'],
    status: 'active'
  },
  {
    id: 3,
    module: '用户管理',
    permissions: ['查看用户'],
    status: 'limited'
  },
  {
    id: 4,
    module: '系统设置',
    permissions: [],
    status: 'disabled'
  }
])

// 角色信息
const roleInfo = ref({
  roleName: '心理咨询师',
  roleLevel: '中级',
  grantDate: '2025-09-25',
  expireDate: '2025-09-25'
})

// 获取状态标签类型
const getStatusType = (status) => {
  switch (status) {
    case 'active': return 'success'
    case 'limited': return 'warning'
    case 'disabled': return 'danger'
    default: return 'info'
  }
}

// 获取状态文本
const getStatusText = (status) => {
  switch (status) {
    case 'active': return '正常'
    case 'limited': return '受限'
    case 'disabled': return '禁用'
    default: return '未知'
  }
}
</script>

<template>
  <div class="permission-page">
    <div class="header">
      <h2>权限管理</h2>
    </div>
    
    <div class="content">
      <!-- 角色信息卡片 -->
      <div class="role-card">
        <h3>角色信息</h3>
        <div class="role-info">
          <div class="info-row">
            <span class="label">当前角色：</span>
            <span class="value">{{ roleInfo.roleName }}</span>
          </div>
          <div class="info-row">
            <span class="label">角色级别：</span>
            <span class="value">{{ roleInfo.roleLevel }}</span>
          </div>
          <div class="info-row">
            <span class="label">授权日期：</span>
            <span class="value">{{ roleInfo.grantDate }}</span>
          </div>
          <div class="info-row">
            <span class="label">到期日期：</span>
            <span class="value">{{ roleInfo.expireDate }}</span>
          </div>
        </div>
      </div>


      <!-- 权限列表 -->
      <el-scrollbar height="300px">
        <div class="permission-card">
          <h3>功能权限</h3>
          <div class="permission-list">
            <div
                v-for="item in permissions"
                :key="item.id"
                class="permission-item"
            >
              <div class="module-header">
                <span class="module-name">{{ item.module }}</span>
                <el-tag :type="getStatusType(item.status)" size="small">
                  {{ getStatusText(item.status) }}
                </el-tag>
              </div>
              <div class="permission-details">
                <div v-if="item.permissions.length > 0" class="permission-tags">
                  <el-tag
                      v-for="permission in item.permissions"
                      :key="permission"
                      size="small"
                      effect="plain"
                  >
                    {{ permission }}
                  </el-tag>
                </div>
                <div v-else class="no-permission">
                  <span>暂无权限</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<style scoped>
.permission-page {
  padding: 20px;
  background-color: #f5f7fa;
  height: 570px;
}

.header {
  margin-bottom: 20px;
}

.header h2 {
  color: #333;
  font-size: 24px;
  font-weight: 500;
}

.content {
  max-width: 1000px;
}

.role-card, .permission-card {
  background: white;
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.role-card h3, .permission-card h3 {
  margin: 0 0 20px 0;
  color: #333;
  font-size: 18px;
  font-weight: 500;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

.role-info {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.info-row {
  display: flex;
  align-items: center;
}

.label {
  color: #666;
  font-weight: 500;
  width: 100px;
}

.value {
  color: #333;
}

.permission-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.permission-item {
  border: 1px solid #eee;
  border-radius: 6px;
  padding: 16px;
}

.module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.module-name {
  font-weight: 500;
  color: #333;
  font-size: 16px;
}

.permission-details {
  margin-left: 0;
}

.permission-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.no-permission {
  color: #999;
  font-style: italic;
}
</style>